Copyright (C) 2020 Andreas Kloeckner
import matplotlib.pyplot as pt
from math import sqrt
a = 0
b = 1
#tau = .3
tau = (sqrt(5)-1)/2
m1 = a + (1-tau) * (b-a)
m2 = a + tau * (b-a)
pt.xlim([a-0.5, b+0.5])
pt.ylim([-0.1, 0.2])
pt.grid()
pt.plot([a,b], [0,0], "ob")
pt.plot([m1, m2], [0,0], "or")
Now see if any function evaluations can be reused if we move to the "left" subinterval:
#clear
pt.xlim([a-0.5, b+0.5])
pt.ylim([-0.1, 0.2])
pt.grid()
pt.plot([a,b], [0,0], "ob")
pt.plot([m1, m2], [0,0], "or")
# Same as above up to this point
pt.plot([0, m2*m1, m2*m2, m2*b], [0.1]*4, "og")
Check numerically:
#clear
m1 - m2**2